﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrExamineSorce.aspx.cs" Inherits="ZX.WebApp.EHR.hrExamineSorce" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>考核打分</title>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery.form.js" type="text/javascript"></script>
     <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
     <script src="../Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
        <script type="text/javascript">
    // <![CDATA[
            var _PageTitle = parent._employeeTitle;
            var fun = "";
            $(document).ready(function () {
                var solutionID = getPar1("solutionID");
                var objectID = getPar1("objectID");
                var roleID = getPar1("roleID");
                var planID = getPar1("planID");
                //parent.document.getElementById("dialog1_h").innerHTML = "考核打分";
                $("#RoleID").val(roleID);
                $("#ObjectID").val(objectID);

                GetRole(roleID);
                GetObject(objectID);
                GetPlan(planID);
            });

            //加载考核人信息
            function GetRole(roleID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationRole&condition=ID='" + roleID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                $("#ExaminationorName").html(list.rows[o].RoleEmpName);
                                $("#Weight").html(list.rows[o].Weight);
                                $("#IsAppraise").html(list.rows[o].IsAppraise);
                               $("#Examinationor").val(list.rows[o].RoleEmpID);
                            }
                        }
                    }
                    else {
                        alert("被考核人信息!");
                        parent.closeWin();
                        return;
                    }
                });
            }

            //加载被考核人信息
            function GetObject(objectID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationObject&condition=ID='" + objectID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                $("#ObjectEmpName").html(list.rows[o].EmpName);
                                $("#EmployeeID").val(list.rows[o].EmployeeID);
                                $("#ObjectEmployeeCode").html(list.rows[o].EmployeeCode);
                                $("#ObjectPostName").html(list.rows[o].PostName);
                            }
                        }
                    }
                    else {
                        alert("被考核人信息!");
                        parent.closeWin();
                        return;
                    }
                });
            }

            //加载考核计划
            function GetPlan(planID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationPlan&condition=ID='" + planID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                $("#SpanPlan").val(list.rows[o].Caption);
                                $("#PlanID").val(list.rows[o].ID);
                                $("#SpanBeginDate").html(list.rows[o].BeginDate);
                                $("#SpanEndDate").html(list.rows[o].EndDate);
                                $("#SolutionName").val(list.rows[o].SolutionName);
                                $("#SolutionRemark").val(list.rows[o].SolutionRemark);
                                $("#SolutionID").val(list.rows[o].SolutionID);
                                GetSolutionStandard(list.rows[o].SolutionID);
                                GetSolutionItem(list.rows[o].SolutionID);
                            }
                        }
                    }
                    else {
                        alert("考核计划为空!");
                        parent.closeWin();
                        return;
                    }
                });
            }

            //加载考核方案标准
            function GetSolutionStandard(solutionID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationStandard&condition=SolutionID='" + solutionID + "'&order=CateoryName asc";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                addtr("tbStandard");
                                //获取最后一行对像，即刚新增的行对像
                                var lastTr = $("#tbStandard tr").last();
                                $("#Cateory", lastTr).val(list.rows[o].CateoryName);
                                $("#StandardSocre", lastTr).val(list.rows[o].Socre);
                                $("#FinishRate", lastTr).val(list.rows[o].FinishRate);
                            }
                        }
                    }
                    else {
                            //
                    }
                });
            }

            //加载考核项目
            function GetSolutionItem(solutionID) {
                //debugger;
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationSolutionItem&condition=ID='" + solutionID + "'&order=ItemSeq asc";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                addtr("tbItem");
                                //获取最后一行对像，即刚新增的行对像
                                var lastTr = $("#tbItem tr").last();
                                $("#Seq", lastTr).val(list.rows[o].ItemSeq);
                                $("#ItemCateoryName", lastTr).val(list.rows[o].ItemCateoryName);
                                $("#ItemName", lastTr).val(list.rows[o].Itemname);
                                $("#ItemID", lastTr).val(list.rows[o].ItemID);
                                $("#ItemRemark", lastTr).val(list.rows[o].ItemRemark);
                                GetResult($("#RoleID").val(), list.rows[o].ItemID, lastTr);
                            }
                        }
                    }
                    else {
                        //
                    }
                });
            }

            //加载已打分考核项目的得分
            function GetResult(roleID, itemID, lastTr) {
                //debugger;
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_ExaminationResult&condition=RoleID='" + roleID + "' and ItemID='" + itemID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                $("#Socre", lastTr).val(list.rows[o].Socre);
                                $("#EffectDate").val(list.rows[o].EffectDate);
                            }
                        }
                    }
                    else {
                        //
                    }
                });
            }



            //增加行
            function addtr(tbName) {
                var tr = $("#" + tbName + " tr").eq(1).clone();
                tr.show();
                tr.appendTo("#" + tbName).removeClass("selectedTr").find(":checkbox").attr("checked", false);
            }

            //删除行
            function deltr(tbName) {
                //遍历tr
                $("#" + tbName + " tr").first().nextAll().each(function () {
                    if ($(this).hasClass("selectedTr")) {
                        $(this).remove();
                    }
                });
            };

            //数据保存
            function Save() {
                //debugger;
                var solutionID = $("#SolutionID").val();
                var planID = $("#PlanID").val();
                var effectDate = $("#EffectDate").val();
                var examinationor = $("#Examinationor").val();
                var employeeID = $("#EmployeeID").val();
                var roleID = $("#RoleID").val();
                var objectID = $("#ObjectID").val();

                //存储行中的数据
                var _TempArray = [];

                if (planID == "") {
                    alert("考核计划ID为空！");
                    return;
                }

                if (effectDate == "") {
                    alert("生效日期为空！");
                    return;
                }
                if (!isDateFormat(effectDate)) {
                    return "生效日期非日期格式！";
                }

                if (solutionID == "") {
                    alert("考核方案ID为空！");
                    return;
                }

                if (examinationor == "") {
                    alert("考核人ID为空！");
                    return;
                }

                if (employeeID == "") {
                    alert("被考核人ID为空！");
                    return;
                }

                //遍历所有考核项目
                $("#tbItem tr").eq(1).nextAll().each(function () {
                    var id = $("#ItemID", this).val();
                    var socre = $("#Socre", this).val();
                    var seq = $("#Seq", this).val();

                    if (id == "") {
                        alert("考核项目为空!");
                        return false;
                    }
                    else if (socre == "") {
                        alert("序号 "+seq+" 的考核项目得分为空!");
                        return false;
                    }
                    else if (id != "" && socre != "") {
                        _TempArray.push($(this).extractObject());
                    }
                });

                if (_TempArray.length == 0) {
                    alert("考核项目有未打分的!");
                    return false;
                }

                //将行转成JSON
                var json = $.toJSON(_TempArray);
                var Url = "hrExaminationAjax.aspx?flag=savesorce&json=" + encodeURI(json) + "&planID=" + planID + "&solutionID=" + solutionID + "&effectDate=" + effectDate + "&examinationor=" + examinationor + "&employeeID=" + employeeID + "&roleID=" + roleID + "&objectID=" + objectID;

                //提交数据
                YAHOO.util.Connect.asyncRequest('POST', Url, {
                    success: function (res) {
                        try {
                            var str = res.responseText;
                            if (str.substring(0, 1) == "1") {
                                alert("数据保存成功!");
                                ClosePage();
                            }
                            else {
                                alert("数据保存失败,请检查");
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }

            //关闭窗口
            function ClosePage() {
                window.parent.$("#tabs").tabs('close', _PageTitle);
            }
    // ]]> 
     </script>
    <style type="text/css">
        body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
        select{width:99%;} 
        td { border: 1px solid #CCCCCC;}
        .textarea{ width: 96%;height: 25px;}	
        .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <input id="RoleID" name="RoleID" type="hidden" />
    <input id="ObjectID" name="ObjectID" type="hidden" />
    <div id="divBody">
        <div id="divBtn">
        <input id="btnSave" name="btnSave" value="提交" type="button" onclick="Save();" />
        <input id="btnClose" name="btnClose" value="关闭" type="button" onclick="ClosePage();" />
        </div>
        <table align="center" class="TableBlock" width="99%" id="tbPlan" name="tbPlan">
            <tr>
	            <td align="left" class="TableData" width="80">【考核人：】
                    <span id="ExaminationorName"></span>
                    <input class="td_value3"  id="Examinationor" name="Examinationor" type="hidden" />
                </td>
	            <td align="left" class="TableData" width="80">【权重(%)：】
                    <span id="Weight"></span>
                </td>
	            <td align="left" class="TableData" width="60">【已考核：】
                    <span id="IsAppraise"></span>
                </td>
	            <td align="left" class="TableData" width="150">【生效日期：】
                <input class="td_value3"  id="EffectDate" name="EffectDate" onclick="WdatePicker();" style="width: 120px" type="text" />
                </td>
            </tr> 
            <tr>
	            <td align="left" class="TableData" width="120" colspan="2">【考核计划：】
		            <input  id="SpanPlan" name="SpanPlan"  type="text"  readonly="readonly"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;width:500px;" />
                    <input  id="PlanID" name="PlanID"  type="hidden" />
                </td>
	            <td align="left" class="TableData" width="150">【开始时间：】
                    <span id="SpanBeginDate"></span>
                </td>
                <td align="left" class="TableData" width="230">
	            【结束时间：】
	            <span id="SpanEndDate"></span>
               </td>
            </tr>
        </table>     
        <table align="center" class="TableBlock" width="99%" id="tbSolution" name="tbSolution">
            <tr>
	            <td align="left" class="TableData" width="150">【考核方案：】
		            <input  id="SolutionName" name="SolutionName"  type="text"  readonly="readonly"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;width:200px;" />
                    <input  id="SolutionID" name="SolutionID"  style="width: 120px" type="hidden" />
                </td>
                <td align="left" class="TableData" width="230">
	            【方案说明：】
		        <input  id="SolutionRemark" name="SolutionRemark"  type="text"  readonly="readonly"  style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;width:500px;" />
               </td>
            </tr>
        </table>
        <table align="center" class="TableBlock" width="99%" id="tbObject" name="tbObject">
            <tr>
	            <td align="left" class="TableData" width="200">【被考核人：】
                    <span id="ObjectEmpName"></span>
                    <input class="td_value3"  id="EmployeeID" name="EmployeeID" type="hidden" />
                </td>
                <td align="left" class="TableData" width="200">
	           【编号：】
	            <span id="ObjectEmployeeCode"></span>
                </td>
               <td align="left" class="TableData" width="200">
                【岗位：】<span id="ObjectPostName"></span>
                </td>
            </tr>
        </table>     
        <br />
        <div id="divStandard">
        <span>【考核标准】</span>
        <table align="center" border="1" id="tbStandard" name="tbStandard" style="border-collapse: collapse" width="99%">
            <tr style="background-color: #e4e7e2">
	            <td align="center">分类</td>
	            <td align="center">得分</td>
	            <td align="center">完成程度(%)</td>
            </tr>
            <tr style="display:none">
	            <td>
                    <input  id="Cateory" name="Cateory"  type="text" readonly="readonly" style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" />
                </td>
	            <td>
		            <input  id="StandardSocre" name="StandardSocre"  type="text" readonly="readonly" style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" />
                </td>
	            <td>
		            <input  id="FinishRate" name="FinishRate"  type="text" readonly="readonly"  style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" />
                </td>
            </tr>
        </table>
        </div><br />
        <div id="divItem">
        <span>【考核项目】</span>
        <table align="center" border="1" id="tbItem" name="tbItem" style="border-collapse: collapse" width="99%">
            <tr style="background-color: #e4e7e2">
	            <td align="center" width="50px">序号</td>
	            <td align="center" width="120">分类</td>
	            <td align="center" width="120">项目名称</td>
	            <td align="center" >项目说明</td>
	            <td align="center" width="80">得分</td>
            </tr>
            <tr style="display:none">
	            <td>
                    <input  id="Seq" name="Seq"  type="text" readonly="readonly" convert="unconvert"  style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;width:50px;" />
                </td>
	            <td>
		            <input  id="ItemCateoryName" name="ItemCateoryName"  type="text" convert="unconvert"  readonly="readonly" style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" />
                </td>
	            <td>
		            <input  id="ItemName" name="ItemName"  type="text" readonly="readonly" convert="unconvert"  style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" />
		            <input  id="ItemID" name="ItemID"  type="hidden"/>
                </td>
	            <td>
		            <input  id="ItemRemark" name="ItemRemark"  type="text"  readonly="readonly" convert="unconvert"  style="background:whitesmoke;border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent;width:700px;" />
                </td>
	            <td>
		            <input  id="Socre" name="Socre"  type="text" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent"  onblur="IsValidateFloat(this);"/>
                </td>
            </tr>
        </table>
        </div>
    </div>
    </form>
</body>
</html>
